package com.hsit.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;



@Repository
public class WorhDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	public Object loginCheck(String username,String passwd){
		String sql="select count(*) from person where name=? and password=?;";
		return jdbcTemplate.queryForObject(sql, new Object[]{username,passwd}, Integer.class);
		
	}
	
	public List userselect(){
		String sql="select * from person;";
		return jdbcTemplate.queryForList(sql);
	}
	
	public void add(String name,String password){
	String sql="insert into person(name,password) values(?,?);";
	jdbcTemplate.update(sql,new Object[]{name,password});
	}
	
	public void delete(String ids){
		String sql="delete from person where id in ("+ids+")";
		jdbcTemplate.update(sql);
		
	}
	
	public List selectName(String ids){
		String sql="select name from person where id in("+ids+")";
	     return jdbcTemplate.queryForList(sql);
		
	}
	
	public void update(String name,String password,String id){
		String sql=" update  person set name=?,password=?  where id=? ";
		jdbcTemplate.update(sql,new Object[]{name,password,id});
		
		
	}
	
}
